<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@include file="../common/common-head.jsp"%>

<body>

<!-- begin #page-container -->

<!-- begin #content -->
<div id="content" class="content">

    <%@include file="../common/common-breadcrumb-add.jsp" %>

    <!-- begin row -->
    <div class="row">
        <!-- begin col-6 -->
        <div class="col-xl-6">
            <!-- begin panel -->
            <div class="panel panel-inverse" data-sortable-id="form-stuff-1">
                <!-- begin panel-heading -->
                <div class="panel-heading">
                    <h4 class="panel-title" >${editObj!=null?'编辑上传服务器':'新增上传服务器'}</h4>
                    <div class="panel-heading-btn">
                        <a href="javascript:;" class="btn btn-xs btn-icon btn-circle btn-default" data-click="panel-expand"><i class="fa fa-expand"></i></a>
                        <a href="javascript:;" class="btn btn-xs btn-icon btn-circle btn-success" data-click="panel-reload"><i class="fa fa-redo"></i></a>
                        <a href="javascript:;" class="btn btn-xs btn-icon btn-circle btn-warning" data-click="panel-collapse"><i class="fa fa-minus"></i></a>
                        <a href="javascript:;" class="btn btn-xs btn-icon btn-circle btn-danger" data-click="panel-remove"><i class="fa fa-times"></i></a>
                    </div>
                </div>
                <!-- end panel-heading -->
                <!-- begin panel-body -->
                <div class="panel-body">
                    <form>
                        <input type="hidden" value="${editObj!=null?editObj.id:''}" id="id">
                        <div class="form-group row m-b-15">
                            <label class="col-form-label col-md-3">服务器名称</label>
                            <div class="col-md-9">
                                <input type="email" class="form-control m-b-5" placeholder="服务器名称" name="name" id="name" value="${editObj!=null?editObj.name:''}" />
                                <small class="f-s-12 text-grey-darker" style="display: none">服务器名称.</small>
                            </div>
                        </div>

                        <div class="form-group row m-b-15">
                            <label class="col-form-label col-md-3">服务器地址</label>
                            <div class="col-md-9">
                                <input type="email" class="form-control m-b-5" placeholder="服务器地址" name="address" id="address" value="${editObj!=null?editObj.address:''}" />
                                <small class="f-s-12 text-grey-darker" style="display: none">服务器地址.</small>
                            </div>
                        </div>

                        <div class="form-group row m-b-15">
                            <label class="col-form-label col-md-3">服务器账号</label>
                            <div class="col-md-9">
                                <input type="email" class="form-control m-b-5" placeholder="服务器账号" name="account" id="account" value="${editObj!=null?editObj.account:''}" />
                                <small class="f-s-12 text-grey-darker" style="display: none">服务器账号.</small>
                            </div>
                        </div>

                        <div class="form-group row m-b-15">
                            <label class="col-form-label col-md-3">服务器密码</label>
                            <div class="col-md-9">
                                <input type="email" class="form-control m-b-5" placeholder="服务器密码" name="password" id="password" value="${editObj!=null?editObj.password:''}" />
                                <small class="f-s-12 text-grey-darker" style="display: none">服务器密码.</small>
                            </div>
                        </div>

                        <div class="form-group row m-b-15">
                            <label class="col-form-label col-md-3">是否开启</label>
                            <!-- switcher -->
                            <div class="switcher col-md-9">
                                <input type="checkbox" name="open" id="open" ${editObj!=null and editObj.open==1?'checked':''} >
                                <label for="open"></label>
                            </div>
                        </div>

                        <div class="form-group row">
                            <div class="col-md-7 offset-md-3">
                                <button type="button" class="btn btn-sm btn-primary m-r-5" id="saveObj">保存</button>
                                <button type="button" class="btn btn-sm btn-default" onclick="back()">返回</button>
                            </div>
                        </div>
                    </form>
                </div>
                <!-- end panel-body -->

            </div>
            <!-- end panel -->

        </div>
        <!-- end col-6 -->
    </div>
    <!-- end row -->

</div>
<!-- end #content -->

<%@include file="../common/common-script.jsp"%>


<script>
    var ctx = '${basePath}'

    function back(){
        window.location.href=ctx+"uploadServer/list"
    }

    $(function(){

        $("#saveObj").click(function(){
            var obj = {}
            obj['id'] = $("#id").val()
            obj['name'] = $("#name").val()
            obj['address'] = $("#address").val()
            obj['account'] = $("#account").val()
            obj['password'] = $("#password").val()
            var open = $('#open').prop('checked')?1:0
            obj['open'] = open

            $.ajax({
                type:'post',
                url:ctx+'uploadServer/add',
                data:JSON.stringify(obj),
                success:function(res){
                    if(res == "1000"){
                        window.location.href=ctx+"uploadServer/list"
                    }
                }
            })

        })
    })

</script>

</body>
</html>
